package com.aji.mapper;

import com.aji.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface LoginMapper {

    @Select("select * from ores.user where id = #{userId}")
    User getByUserId(Long userId);

    @Select("        select distinct m.menu_name\n" +
            "        from\n" +
            "            ores.role_user\n" +
            "                left join ores.role r on r.id = role_user.role_id\n" +
            "                left join ores.role_menu rm on r.id = rm.role_id\n" +
            "                left join ores.menu m on rm.menu_id = m.id\n" +
            "        where user_id = #{id}")
    List<String> selectPermsByUserId(Integer id);

    @Select("select * from ores.user where username = #{username}")
    User getByUserName(String username);

    @Select("select role_name from role\n" +
            "left join role_user ru on role.id = ru.role_id\n" +
            "where ru.user_id =#{id}")
    List<String> getRoleById(Integer id);
}
